package cgb2202.recruitment01.controller;

import cgb2202.recruitment01.entity.Emp;
import cgb2202.recruitment01.entity.Intention;
import cgb2202.recruitment01.mapper.IntentionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
public class IntentionController {
    @Autowired(required = false)
    IntentionMapper mapper;
    @RequestMapping("/intention/select")
    public Intention select(HttpSession session){
        System.out.println("进来了");
        Emp emp=(Emp) session.getAttribute("currentUser");
        System.out.println(mapper.getIntentionByEmail(emp.getEmail()));
        return mapper.getIntentionByEmail(emp.getEmail());
    }

    @RequestMapping("/intention/insert")
    public void insertEmpInfo(@RequestBody Intention intention, HttpSession session){
        System.out.println("进来了");
        Emp emp=(Emp) session.getAttribute("currentUser");
        int count=mapper.selectByUid(emp.getId());
        int uid=emp.getId();
        System.out.println(emp);
        System.out.println(uid);
        System.out.println(intention);
        if (count == 0){
            mapper.insertIntention(uid,intention);
        }else{
            mapper.updateIntention(uid,intention);
        }
        System.out.println(emp.getEmail());
        mapper.getIntentionByEmail(emp.getEmail());
    }
}
